<?php


class WSB_View_Helper_FormCaptcha extends Zend_View_Helper_FormElement
{

	/**
	 * @param string $name
	 * @param string $value
	 * @param array $attribs
	 * @return string
	 */
	public function formCaptcha($name, $value = null, $attribs = null)
	{
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

		$captcha = new WSB_Captcha_Number($value);
		$captcha->printNumber();

		$captchaCrypted = $name.'_crypted';
		$pos = strpos($name, ']');
		if($pos !== false) {
			$part1 = substr($name, 0, $pos);
			$part2 = substr($name, $pos);
			$captchaCrypted = $part1 . '_crypted' . $part2;
		}

		$idHidden = isset($attribs['id']) ? $attribs['id'] . '-crypted' : '';
		$elements  = $this->view->formHidden($captchaCrypted, crypt($value, Zend_Registry::get('Zend_Config')->application->cryptSalt), array('id' => $idHidden));
		$elements .= $this->view->formText($name, null, $attribs);
		return $elements;
	}

}
